import jieba

word = ''
result_num = []
result = {}
count5 = []

with open('./test.txt','rb') as f:
    inner = f.read()
    word = jieba.lcut(inner)
    f.close()

for i in word:
    result[i]= result.get(i,0)+1

for j in result.keys():
    result_num.append(result[j])

result_num.sort(reverse=True)
s = list(set(result_num))
s.sort(reverse=True)

count = 0
for j in s:
   for i in result.keys():
      if result[i] == j and len(i)>1 and i !='\r\n':
          if count>=5:
              break
          else:
              count+=1
              count5.append(i)

with open('./output.txt','a',encoding='utf-8') as f:
    for i in count5:
        out = "{0}  {1} 次\n".format(i,result[i])
        f.write(out)
    f.close()
